<?php

/**
 * 侧边栏组件、页面模块
 */
defined('EMLOG_ROOT') || exit('access denied!');
?>
<?php
/**
 * 文章  links
 */
function blog_links()
{
    global $CACHE;
    $link_cache = $CACHE->readCache('link');
    //if (!blog_tool_ishome()) return;#只在首页显示友链去掉双斜杠注释即可
?>
    <?php
    foreach ($link_cache as $value) :
        $icon = isset($value['icon']) ? $value['icon'] : '';
    ?>
        <li>
            <?php if ($icon) : ?>
                <img src="<?= $icon ?>" alt="<?= $value['link'] ?>" title="<?= $value['link'] ?>">
            <?php else: ?>
                <img src="<?= roundImage() ?>" alt="<?= $value['link'] ?>" title="<?= $value['link'] ?>">
            <?php endif ?>
            <a href="<?= $value['url'] ?>" title="<?= $value['des'] ?>" target="_blank"><?= $value['link'] ?></a>
        </li>
    <?php endforeach ?>
<?php } ?>
<?php
/**
 * 侧边栏：链接
 */
function widget_link($title)
{
    global $CACHE;
    $link_cache = $CACHE->readCache('link');
    //if (!blog_tool_ishome()) return;#只在首页显示友链去掉双斜杠注释即可
?>
    <div class="aside_container aside_link immersion-hide">
        <h3 class="sidebar_title">
            <i class="iconfont icon-lianjie"></i>
            <?= $title ?>
        </h3>
        <div class="link">
            <ul class="aside_list link_list">
                <?php
                foreach ($link_cache as $value) :
                    $icon = isset($value['icon']) ? $value['icon'] : '';
                ?>
                    <li>
                        <?php if ($icon) : ?>
                            <!-- <img src="<?= $icon ?>" height="20" width="20" class="rounded" style="margin-right: 5px;"> -->
                        <?php endif; ?>
                        <a href="<?= $value['url'] ?>" title="<?= $value['des'] ?>" target="_blank"><?= $value['link'] ?></a>
                    </li>
                <?php endforeach ?>
            </ul>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：个人资料
 */
function widget_blogger($title)
{
    if (!UID || !blog_tool_ishome()) return;
    $userModel = new User_Model();
    $uid = UID;
    $name = '';
    $description = '';
    $avatar = BLOG_URL . "admin/views/images/avatar.svg";
    $user = $userModel->getOneUser($uid);
    if ($user) {
        $name = $user['nickname'];
        $description = $user['description'];
        $avatar = User::getAvatar($user['photo']);
    }
?>

    <div class="article-author immersion-hide">
        <div class="article-author-content" itemscope="" itemtype="http://schema.org/Person">
            <a class="article-author-head" href="<?= URL::author($uid) ?>" target="_self" rel="author">
                <div class="article-author-avatar">
                    <img src="<?= $avatar ?>" alt="<?= $name ?>" width="80" height="80">
                </div>
                <div class="article-author-info">
                    <div class="article-author-name" itemprop="name"><?= $name ?></div>
                    <div class="article-author-group"><?= $description ?></div>
                </div>
            </a>
            <div class="article-author-body">
                <div class="author_body">
                    <div class="author_body_left">
                        <div class="date"><?= getTimePeriod() ?> 好</div>
                        <div class="date_desc">
                            社区有你真好
                        </div>
                    </div>
                    <div class="author_body_right">
                        <button class="yublog_button">
                            签到
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 文章页面
 */
function blog_widget_blogger($uid, $logid, $views, $date)
{
    if (!$uid) return;
    $userModel = new User_Model();
    $name = '';
    $description = '';
    $avatar = BLOG_URL . "admin/views/images/avatar.svg";
    $user = $userModel->getOneUser($uid);
    if ($user) {
        $name = $user['nickname'];
        $description = $user['description'];
        $avatar = User::getAvatar($user['photo']);
    }

    $likes = log_likes($logid);

    $like_num = $likes ? count($likes) : 0;
?>

    <div class="article-author immersion-hide">
        <div class="article-author-content" itemscope="" itemtype="http://schema.org/Person">
            <a class="article-author-head" href="<?= URL::author($uid) ?>" target="_self" rel="author">
                <div class="article-author-avatar">
                    <img src="<?= $avatar ?>" alt="<?= $name ?>" width="80" height="80">
                </div>
                <div class="article-author-info">
                    <div class="article-author-name" itemprop="name"><?= $name ?></div>
                    <div class="article-author-group"><?= $description ?></div>
                </div>
            </a>
            <div class="article-author-body">
                <div class="article-author-item">
                    <i class="iconfont icon-dianzan1 article-author-item-icon"></i>
                    <span class="article-author-item-text">获得点赞 <?= $like_num ?></span>
                </div>
                <div class="article-author-item">
                    <i class="iconfont icon-liulan article-author-item-icon"></i>
                    <span class="article-author-item-text">文章被阅读 <?= $views ?></span>
                </div>
                <div class="article-author-item">
                    <i class="iconfont icon-gengxin article-author-item-icon"></i>
                    <span class="article-author-item-text">最后更新 <?= $date ?></span>
                </div>
            </div>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：日历
 */
function widget_calendar($title)
{ ?>
    <div class="aside_container aside_link immersion-hide">
        <h3 class="sidebar_title">
            <i class="iconfont icon-rili"></i>
            <?= $title ?>
        </h3>
        <div class="calendar">
            <script src="<?= TEMPLATE_URL ?>static/scripts/calendar.js"></script>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：标签
 */
function widget_tag($title)
{
    global $CACHE;
    $tag_cache = $CACHE->readCache('tags');
?>
    <div class="aside_container tags immersion-hide">
        <h3 class="sidebar_title">
            <i class="iconfont icon-tag"></i>
            <?= $title ?>
        </h3>
        <div class=" tags_list">
            <ul class="aside_list">
                <?php foreach ($tag_cache as $value) : ?>

                    <li class="link"><a href="<?= Url::tag($value['tagurl']) ?>" title="<?= $value['usenum'] ?> 篇文章"><?= $value['tagname'] ?></a></li>
                <?php endforeach ?>
            </ul>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：分类
 */
function widget_sort($title)
{
    global $CACHE;
    $sort_cache = $CACHE->readCache('sort'); ?>
    <div class="aside_container sort immersion-hide">
        <h3 class="sidebar_title"><i class="iconfont icon-folderOpen"></i><?= $title ?></h3>

        <div class="sort_list">
            <ul class="aside_list category_list">
                <?php
                foreach ($sort_cache as $value) :
                    if ($value['pid'] != 0) continue; ?>
                    <li class="">
                        <a href="<?= Url::sort($value['sid']) ?>"><?= $value['sortname'] ?>&nbsp;&nbsp;<?= (($value['lognum']) > 0) ? '(' . ($value['lognum']) . ')' : '' ?></a>
                    </li>
                <?php endforeach ?>
            </ul>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：最新微语
 */
function widget_twitter($title)
{
    global $CACHE;
    $index_newtwnum = Option::get('index_newtwnum') ?: 10;
    $Twitter_Model = new Twitter_Model();
    $ts = $Twitter_Model->getTwitters('', 1, $index_newtwnum);
    $user_cache = $CACHE->readCache('user');
?>
    <div class="aside_container twiter immersion-hide">
        <h3 class="sidebar_title">
            <i class="iconfont icon-weiyu"></i>
            <?= $title ?>
        </h3>
        <div class="comments_list aside_twiter">
            <ul class="list">
                <?php foreach ($ts as $value) :
                    $author = $user_cache[$value['author']]['name'];
                ?>
                    <li class="item">
                        <div class="user">
                            <img class="avatar" src="<?= author_head($value['author']) ?>" alt="">
                            <div class="info">
                                <div class=""> <?= $author ?> </div>
                                <span class="date">
                                    <?= $value['date'] ?>
                                </span>
                            </div>
                        </div>
                        <div class="twiter_content">
                            <?= $value['t']; ?>
                        </div>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：最新评论
 */
function widget_newcomm($title)
{
    global $CACHE;
    $com_cache = $CACHE->readCache('comment');
?>

    <div class="aside_container comments immersion-hide">
        <h3 class="sidebar_title">
            <i class="iconfont icon-pinglun"></i>
            <?= $title ?>
        </h3>

        <div class="comments_list">
            <ul class="list">
                <?php
                foreach ($com_cache as $value) :
                    $url = Url::comment($value['gid'], $value['page'], $value['cid']);
                    $avatar = getEmUserAvatar($value['uid'], $value['mail']);
                ?>
                    <li class="item">
                        <div class="user">

                            <div class="avatar yublog_user_avatar">
                                <img class="" src="<?= $avatar ?>" alt="<?= $value['name'] ?>用户头像">
                            </div>
                            <div class="info">
                                <div class=""> <?= $value['name'] ?> </div>
                                <span class="date">
                                    <?= smartDate($value['date']) ?>
                                </span>
                            </div>
                        </div>
                        <div class="reply">
                            <a class="link aside-reply-content" href="<?= $url ?>">
                                <?= $value['content'] ?>
                            </a>

                        </div>
                    </li>
                <?php endforeach ?>

            </ul>
        </div>
    </div>

<?php } ?>
<?php
/**
 * 侧边栏：最新文章
 */
function widget_newlog($title)
{
    global $CACHE;
    $newLogs_cache = $CACHE->readCache('newlog');
    $i = 0;
?>
    <div class="aside_container article immersion-hide">
        <h3 class="sidebar_title">
            <i class="iconfont icon-gengxin"></i>
            <?= $title ?>
        </h3>
        <div class="article_list">
            <ul class="list">
                <?php foreach ($newLogs_cache as $value) : ?>
                    <li class="item">
                        <span class="type_index"><?= ++$i ?></span>
                        <a class="link" href="<?= Url::log($value['gid']) ?>">
                            <?= $value['title'] ?>
                        </a>
                    </li>

                <?php endforeach ?>
            </ul>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：热门文章
 */
function widget_hotlog($title)
{
    $index_hotlognum = Option::get('index_hotlognum');
    $Log_Model = new Log_Model();
    $hotLogs = $Log_Model->getHotLog($index_hotlognum);
    $i = 0; ?>
    <div class="aside_container article immersion-hide">
        <h3 class="sidebar_title">
            <i class="iconfont icon-huore"></i>
            <?= $title ?>
        </h3>
        <div class="article_list">
            <ul class="list">
                <?php foreach ($hotLogs as $value) : ?>
                    <li class="item">
                        <span class="type_index"><?= ++$i ?></span>
                        <a class="link" href="<?= Url::log($value['gid']) ?>">
                            <?= $value['title'] ?>
                        </a>
                    </li>
                <?php endforeach ?>
            </ul>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：搜索
 */
function widget_search($title)
{ ?>
    <div class="aside_container aside_link immersion-hide">
        <h3 class="sidebar_title">
            <i class="iconfont icon-sousuo"></i>
            <?= $title ?>
        </h3>

        <div class="yublog_search">
            <form class="header_search_form" action="/?keyword">
                <input class="header_search_input" type="text" name="keyword" placeholder="输入关键字搜索" autocomplete="off">
                <label for="header_search_input" class="header_search_btn" tabindex="0">
                    <i class="iconfont icon-sousuo"></i>
                </label>
                <div class="search_history">
                    <div class="search_history_head">
                        <span class="search-history-head-title">搜索历史</span>
                        <span class="search_history_clear_btn">清空</span>
                    </div>
                    <div class="search_history_list"></div>
                </div>
            </form>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：归档
 */
function widget_archive($title)
{
    $bar_id = "36";
    global $CACHE;
    $record_cache = $CACHE->readCache('record');
?>
    <div class="aside_container record immersion-hide">
        <h3 class="sidebar_title">
            <i class="iconfont icon-cundang"></i><?= $title ?>
        </h3>
        <div class="sort_list">
            <ul class="aside_list record_list">
                <?php foreach ($record_cache as $value) : ?>
                    <li><a href="<?= Url::record($value['date']) ?>"><?= $value['record'] ?> (<?= $value['lognum'] ?>)</a></li>
                <?php endforeach ?>
            </ul>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 侧边栏：自定义组件
 */
function widget_custom_text($title, $content)
{ ?>
    <div class="aside_container immersion-hide">
        <?php if ($title) : ?>
            <h3 class="sidebar_title day">
                <?= $title ?>
            </h3>
        <?php endif ?>
        <div class="">
            <?= $content ?>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 
 */
function log_tree_content()
{ ?>
    <div class="aside_container aside_sticky directory-tree">
        <h3 class="sidebar_title">
            文章目录
        </h3>
        <div class="directory-tree-content">
            <div class="directory-tree-body">
                <?php getJJDirectoryTree() ?>
            </div>
        </div>
    </div>
<?php } ?>
<?php
/**
 * 页顶：导航
 */
function blog_navi()
{
    global $CACHE;
    $navi_cache = $CACHE->readCache('navi');
?>
    <div class="blog-header-nav" id="navbarResponsive">
        <ul class="nav-list">
            <?php
            foreach ($navi_cache as $value):
                if ($value['pid'] != 0) {
                    continue;
                }
                if ($value['url'] == 'admin' && (!User::isVisitor())):
            ?>
                    <li class="list-item list-menu"><a href="<?= BLOG_URL ?>admin/" class="nav-link">管理</a></li>
                    <li class="list-item list-menu"><a href="<?= BLOG_URL ?>admin/account.php?action=logout" class="nav-link">退出</a></li>
                <?php
                    continue;
                endif;
                $newtab = $value['newtab'] == 'y' ? 'target="_blank"' : '';
                $value['url'] = $value['isdefault'] == 'y' ? BLOG_URL . $value['url'] : trim($value['url'], '/');
                $current_tab = BLOG_URL . trim(Dispatcher::setPath(), '/') == $value['url'] ? 'active' : '';
                ?>
                <?php if (!empty($value['children']) || !empty($value['childnavi'])) : ?>
                    <li class="list-item list-menu">
                        <?php if (!empty($value['children'])): ?>
                            <a class="nav-link has-down" id="nav_link" href="<?= $value['url'] ?>" <?= $newtab ?>><?= $value['naviname'] ?></a>
                            <ul class="dropdown-menus">
                                <?php foreach ($value['children'] as $row) {
                                    echo '<li class="list-item list-menu"><a class="nav-link" href="' . Url::sort($row['sid']) . '">' . $row['sortname'] . '</a></li>';
                                } ?>
                            </ul>
                        <?php endif ?>
                        <?php if (!empty($value['childnavi'])) : ?>
                            <a class='nav-link has-down' id="nav_link" href="<?= $value['url'] ?>" <?= $newtab ?>><?= $value['naviname'] ?></a>
                            <ul class="dropdown-menus">
                                <?php foreach ($value['childnavi'] as $row) {
                                    $newtab = $row['newtab'] == 'y' ? 'target="_blank"' : '';
                                    echo '<li class="list-item list-menu"><a class="nav-link" href="' . $row['url'] . "\" $newtab >" . $row['naviname'] . '</a></li>';
                                } ?>
                            </ul>
                        <?php endif ?>
                    </li>
                <?php else: ?>
                    <li class="list-item list-menu"><a class="nav-link" href="<?= $value['url'] ?>" <?= $newtab ?>><?= $value['naviname'] ?></a></li>
                <?php endif ?>
            <?php endforeach ?>
            <li class="list-item list-menu"><span class="iconfont icon-DarkTheme" id="theme-toggle"></span></li>
        </ul>
    </div>
<?php } ?>
<?php
function blog_navList()
{
    $Sort_Model = new Sort_Model();
    $r = $Sort_Model->getSorts();

?>
    <div class="nav-container">
        <div class="nav-content">
            <div class="nav-list">
                <?php foreach ($r as $value):
                    if ($value['pid'] != 0) {
                        continue;
                    }
                ?>

                    <div class="nav-list-item nav-list-item-parent">
                        <a class="nav-list-item-parent-name" href="<?= URL::sort($value['sid']) ?>"><?= $value['sortname'] ?></a>
                        <?php if (count($value['children'])): ?>
                            <div class="nav-list-secondary">
                                <?php foreach ($value['children'] as $child) :
                                    $childValue = $Sort_Model->getOneSortById($child);
                                ?>
                                    <a class="nav-list-secondary-item" href="<?= URL::sort($child) ?>">
                                        <?= $childValue['sortname'] ?>
                                    </a>
                                <?php endforeach ?>
                            </div>
                        <?php endif ?>
                    </div>
                <?php endforeach ?>
            </div>
        </div>
    </div>
    <div class="nav-secondary-warp"></div>
<?php } ?>
<?php
function blog_nav()
{
    global $CACHE;
    $navi_cache = $CACHE->readCache('navi');

?>
    <?php
    foreach ($navi_cache as $value):
        if ($value['pid'] != 0) {
            continue;
        }
        if ($value['url'] == 'admin' && (!User::isVisitor())):
    ?>
            <li class=""><a class="header_nav_list_item" href="<?= BLOG_URL ?>admin/" class="nav-link">管理</a></li>
            <li class=""><a class="header_nav_list_item" href="<?= BLOG_URL ?>admin/account.php?action=logout" class="nav-link">退出</a></li>
        <?php
            continue;
        endif;
        $newtab = $value['newtab'] == 'y' ? 'target="_blank"' : '';
        $value['url'] = $value['isdefault'] == 'y' ? BLOG_URL . $value['url'] : trim($value['url'], '/');
        $current_tab = BLOG_URL . trim(Dispatcher::setPath(), '/') == $value['url'] ? 'active' : '';
        ?>
        <?php if (empty($value['children']) || empty($value['childnavi'])) : ?>
            <li class=""><a class="header_nav_list_item" href="<?= $value['url'] ?>" <?= $newtab ?>><?= $value['naviname'] ?></a></li>
        <?php endif ?>
    <?php endforeach ?>

<?php } ?>
<?php
/**
 * 文章列出卡片：置顶标志
 */
function topflg($top, $sortop = 'n', $sortid = null)
{
    $ishome_flg = '<span class="log-topflg" >置顶</span>';
    $issort_flg = '<span class="log-topflg" >分类置顶</span>';
    if (blog_tool_ishome()) {
        echo $top == 'y' ? $ishome_flg : '';
    } elseif ($sortid) {
        echo $sortop == 'y' ? $issort_flg : '';
    }
}

?>
<?php
/**
 * 文章详情页：编辑链接
 */
function editflg($logid, $author)
{
    $editflg = User::haveEditPermission() || $author == UID ? '<a href="' . BLOG_URL . 'admin/article.php?action=edit&gid=' . $logid . '" target="_blank"><span class="iconfont icon-edit"></span></a>' : '';
    echo $editflg;
}

?>
<?php
/**
 * 文章详情页：分类
 */
function blog_sort($sortID)
{
    $Sort_Model = new Sort_Model();
    $r = $Sort_Model->getOneSortById($sortID);
    $sortName = isset($r['sortname']) ? $r['sortname'] : '';
?>
    <?php if (!empty($sortName)) { ?>
        <a href="<?= Url::sort($sortID) ?>"><?= $sortName ?></a>
<?php }
} ?>
<?php
/**
 * 首页文章列表：分类
 */
function bloglist_sort($sortID)
{
    $Sort_Model = new Sort_Model();
    $r = $Sort_Model->getOneSortById($sortID);
    $sortName = isset($r['sortname']) ? $r['sortname'] : '';
?>
    <?php if (!empty($sortName)) { ?>
        <span class="loglist-sort">
            <a href="<?= Url::sort($sortID) ?>"><?= $sortName ?></a>
        </span>
<?php }
} ?>
<?php
/**
 * 首页文章列表和文章详情页：标签
 */
function blog_tag($blogid)
{
    $tag_model = new Tag_Model();
    $tag_ids = $tag_model->getTagIdsFromBlogId($blogid);
    $tag_names = $tag_model->getNamesFromIds($tag_ids);
    if (!empty($tag_names)) {
        $tag = '';
        foreach ($tag_names as $value) {
            $tag .= "    <a href=\"" . Url::tag(rawurlencode($value)) . "\" class='tags' title='标签' >" . htmlspecialchars($value) . '</a>';
        }
        echo $tag;
    }
}

?>
<?php
/**
 * 首页文章列表和文章详情页：作者
 */
function blog_author($uid)
{
    $User_Model = new User_Model();
    $user_info = $User_Model->getOneUser($uid);
    $author = $user_info['nickname'];
    echo '<a href="' . Url::author($uid) . "\">$author</a>";
}

?>
<?php
/**
 * 文章详情页：相邻文章
 */
function neighbor_log($neighborLog)
{
    extract($neighborLog) ?>
    <?php if ($prevLog): ?>
        <span class="prev-log"><a href="<?= Url::log($prevLog['gid']) ?>" title="上一篇：<?= $prevLog['title'] ?>"><span class="iconfont icon-prev"></span></a></span>
    <?php endif ?>
    <?php if ($nextLog): ?>
        <span class="next-log"><a href="<?= Url::log($nextLog['gid']) ?>" title="下一篇：<?= $nextLog['title'] ?>"><span class="iconfont icon-next"></span></a></span>
    <?php endif ?>
<?php } ?>
<?php
/**
 * 文章详情页：评论列表
 */
function blog_comments($comments, $comnum)
{
    extract($comments);
    foreach ($commentStacks as $cid):
        $comment = $comments[$cid];
?>
        <div class="comment" id="<?= $comment['cid'] ?>">
            <?php
            $avatar = getEmUserAvatar($comment['uid'], $comment['mail']);
            ?>

            <li class="comment-list-item comment-parent">
                <div class="comment-list-media-wrapper">
                    <div id="comment-<?= $comment['cid'] ?>" class="comment-list-media">
                        <div class="comment-list-media-avatar">
                            <img class="avatar" src="<?= $avatar ?>" alt="<?= $comment['poster'] ?>" width="40" height="40">
                        </div>
                        <div class="comment-list-media-content">
                            <div class="comment-list-media-head">
                                <div class="comment-list-media-head-left">
                                    <h5 class="comment-list-item-author"><a href="javascript:;" rel="external nofollow"><?= $comment['poster'] ?> </a></h5>
                                    <!-- <span class="comment-list-item-browser">Google Chrome</span> -->
                                    <!-- <span class="comment-list-item-system">Windows 10</span> -->
                                </div>
                                <div class="comment-list-media-head-right">
                                    <time class="comment-list-item-time" datetime="<?= $comment['date'] ?>" itemprop="datePublished">
                                        <?= $comment['date'] ?>
                                    </time>
                                </div>
                            </div>
                            <div class="comment-list-media-body">
                                <div class="comment-list-item-comment">
                                    <?= $comment['content'] ?> </div>
                                <div class="comment-list-item-outer">
                                    <div class="comment-list-item-reply">
                                        <a href="javascript:;" rel="nofollow" onclick="return comment.reply_link(<?= $comment['cid'] ?>);">
                                            <i class="iconfont icon-pinglun comment-list-item-reply-icon"></i>回复</a>
                                    </div>
                                </div>


                            </div>
                        </div>
                    </div>
                </div>
            </li>
            <?php blog_comments_children($comments, $comment['children']) ?>
        </div>
    <?php endforeach ?>
    <div class="comment-pagination">
        <ol class="comment-page">
            <?= $commentPageUrl; ?>
        </ol>
    </div>
<?php } ?>
<?php
/**
 * 文章详情页：子评论
 */
function blog_comments_children($comments, $children)
{
    foreach ($children as $child):
        $comment = $comments[$child];
        $avatar = getEmUserAvatar($comment['uid'], $comment['mail']);
?>
        <div class="comment-children">
            <ol class="comment-list">
                <li class="comment-list-item comment-parent">
                    <div id="comment-<?= $comment['cid'] ?>" class="comment-list-media-wrapper">
                        <div class="comment-list-media" id="<?= $comment['cid'] ?>">
                            <div class="comment-list-media-avatar">
                                <img class="avatar" src="<?= $avatar ?>" alt="<?= $comment['poster'] ?>" width="40" height="40">
                            </div>
                            <div class="comment-list-media-content">
                                <div class="comment-list-media-head">
                                    <div class="comment-list-media-head-left">
                                        <h5 class="comment-list-item-author"><a href="http://blog.13log.cn" rel="external nofollow"><?= $comment['poster'] ?> </a></h5>
                                        <!-- <span class="comment-list-item-browser">Google Chrome</span> -->
                                        <!-- <span class="comment-list-item-system">Windows 10</span> -->
                                    </div>
                                    <div class="comment-list-media-head-right">
                                        <time class="comment-list-item-time" datetime="<?= $comment['date'] ?>" itemprop="datePublished">
                                            <?= $comment['date'] ?>
                                        </time>
                                    </div>
                                </div>
                                <div class="comment-list-media-body">
                                    <div class="comment-list-item-comment">
                                        <?= $comment['content'] ?> </div>
                                    <div class="comment-list-item-outer">
                                        <div class="comment-list-item-reply">
                                            <a href="javascript:;" rel="nofollow" onclick="return comment.reply_link(<?= $comment['cid'] ?>);">
                                                <i class="iconfont icon-pinglun comment-list-item-reply-icon"></i>回复</a>
                                        </div>
                                    </div>


                                </div>
                            </div>
                        </div>
                    </div>
                </li>
                <?php blog_comments_children($comments, $comment['children']) ?>
            </ol>
        </div>
    <?php endforeach ?>
<?php } ?>
<?php
/**
 * 文章详情页：评论表单
 */
function blog_comments_post($logid, $ckname, $ckmail, $ckurl, $verifyCode, $allow_remark)
{
    $isLoginComment = Option::get('login_comment');
?>
    <?php if ($allow_remark == 'y'): ?>
        <?php if ($isLoginComment == 'y' && !ISLOGIN) : ?>
            <div class="comment-off">-- 请登录后评论 --</div>
        <?php else: ?>
            <div id="" class="comment-form-wrap">
                <form class="comment-form" method="post" action="<?= BLOG_URL ?>index.php?action=addcom" id="comment-form" role="form">
                    <div class="comment-form-body">
                        <div class="comment-form-avatar">
                            <img src="<?= getEmUserAvatar(UID, $ckmail) ?>">
                        </div>
                        <div class="comment-form-content">
                            <input type="hidden" name="gid" value="<?= $logid ?>" />
                            <?php if (User::isVisitor() && $isLoginComment === 'n'): ?>
                                <div class="comment-form-input-group">
                                    <input class="comment-form-input" type="text" name="comname" placeholder="昵称" value="<?= $ckname ?>" required pattern="\S+.*" />
                                    <input class="comment-form-input" type="email" name="commail" placeholder="Email" value="<?= $ckmail ?>" />
                                    <input class="comment-form-input" type="url" name="commurl" placeholder="" value="" />
                                </div>
                            <?php endif ?>
                            <div class="comment-form-combination">
                                <div class="comment-form-textarea-wrap">
                                    <textarea id="textarea" class="comment-form-textarea" name="comment" placeholder="请填写真实邮箱方便站长联系，并回复有效的内容！回复有效的内容！有效的内容！" required></textarea>
                                </div>
                                <div class="comment-form-footer">
                                    <div class="comment-form-tool">
                                    </div>
                                    <div class="comment-form-btn-wrap">
                                        <button class="comment-form-btn comment-form-cancel hidden" type="button">放弃</button>
                                        <button class="comment-form-btn comment-form-submit" type="submit">评论</button>
                                    </div>
                                </div>
                            </div>

                            <input type="hidden" name="pid" id="comment-pid" value="0" tabindex="1" />

                        </div>
                    </div>
                </form>
            </div>
        <?php endif ?>
    <?php else:  ?>
        <div class="comment-off">-- 评论已关闭 --</div>
    <?php endif ?>


<?php } ?>
<?php
/**
 * 判断函数：是否是首页
 */
function blog_tool_ishome()
{
    if (BLOG_URL . trim(Dispatcher::setPath(), '/') == BLOG_URL) {
        return true;
    } else {
        return FALSE;
    }
}

?>
<?php
function getEmUserAvatar($uid, $mail)
{
    $avatar = '';
    if ($uid) {
        $userModel = new User_Model();
        $user = $userModel->getOneUser($uid);
        $avatar = $user['photo'];
    } elseif ($mail) {
        $avatar = getGravatar($mail);
    }
    return $avatar ?: BLOG_URL . "admin/views/images/avatar.svg";
}
?>